package com.example.yyy

import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.RectF
import android.util.AttributeSet



class RoundTextView@JvmOverloads constructor(
    context: Context, attrs: AttributeSet? = null, defStyle: Int = 0)
    : androidx.appcompat.widget.AppCompatTextView(context, attrs,defStyle){

    //
    override fun onDraw(canvas: Canvas?) {
        super.onDraw(canvas)
        //通过画笔Paint在画布Canvas绘制图按
        val paint = Paint()
        paint.color = Color.RED //颜色
        paint.strokeWidth = 2f //笔粗细
        paint.style = Paint.Style.FILL_AND_STROKE//笔样式
        paint.isAntiAlias = true //笔无锯齿
        //用指定的坐标创建一个新矩形
        val rectF = RectF(1f,1f,(this.width-1).toFloat(),(this.height-1).toFloat())
        //绘制圆角矩形
        canvas?.drawRoundRect(rectF,10f,10f,paint)
    }
}
